class Solution:
    def lengthOfLongestSubstring(self,s):
        d = {}
        cur = 0
        res = 0
        for i, c in enumerate(s):
            if c in d:
                cur = min(cur+1, i-d[c])
            else:
                cur = cur + 1
            d[c] = i
            res = max(res,cur)
        return res

s = Solution()
print s.lengthOfLongestSubstring("abcabcbb")
